<template>
  <div class="resource-item-wrap">
    <div class="right">
      <div class="top">
        <resource-info
          :resource-name="item.resourceName"
          :account-name-organization="item.accountNameOrganization"
          :resource-id="item.resourceId"
          account-name-platform="none"
          account-belong-name="none"
        />
      </div>
      <div class="bottom">
        <el-tooltip v-if="(item.platformTypeName ? item.platformTypeName.length : 0) + (item.accountBelongName ? item.accountBelongName.length : 0) > 7" class="item" effect="dark" placement="left-start">
          <div slot="content">
            <span>{{ item.platformTypeName }}</span>
            <span v-if="item.platformTypeName && item.accountBelongName" style="margin: 0 3px 0 0px">|</span>
            <span>{{ item.accountBelongName }}</span>
          </div>
          <div class="ellipsisOne">
            <span>{{ item.platformTypeName }}</span>
            <span v-if="item.platformTypeName && item.accountBelongName" style="margin: 0 3px 0 0px">|</span>
            <span>{{ item.accountBelongName }}</span>
          </div>
        </el-tooltip>
        <div v-else class="ellipsisOne">
          <span v-if="resourceIsShowPlatform">{{ item.platformTypeName }}</span>
          <span v-if="resourceIsShowPlatform && item.platformTypeName && item.accountBelongName" style="margin: 0 3px 0 0px">|</span>
          <span>{{ item.accountBelongName }}</span>
        </div>
      </div>
    </div>
    <div class="left">
      <div v-if="hasRouteAuth('crm:subcribe:add') || hasRouteAuth('crm:subcribe:all')" class="btn"><i class="el-icon-plus" @click="create" /></div>
    </div>
  </div>
</template>
<script>
import { hasRouteAuth } from '@/utils/permission';
import ResourceInfo from '@/components/ResourceInfo';
import { mapGetters } from 'vuex';
export default {
  name: 'ResourceItem',
  components: { ResourceInfo },
  props: {
    item: {
      type: Object,
      default: () => null
    }
  },
  computed: {
    ...mapGetters([
      'resourceIsShowPlatform'
    ])
  },
  methods: {
    hasRouteAuth,
    create() {
      this.$emit('create', this.item);
    }
  }
};
</script>
<style lang="scss" scoped>
.resource-item-wrap {
  display: flex;
  align-items: center;
  .right {
    // flex: 1;
    display: flex;
    width: 80%;
    flex-direction: column;
    align-content: space-between;
    height: 45px;
    .top {
      color: #333333;
      font-size: 14px;
    }
    .bottom {
      width: 130px;
      overflow: hidden;
      text-overflow:ellipsis;
      white-space: nowrap;
      color: #999999;
      font-size: 14px;
    }
  }
  .left {
    flex: 1;
    display: flex;
    justify-content: flex-end;
    .btn {
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      width:32px;
      height:32px;
      font-size: 16px;
      font-weight: 500;
      color: #406EFF;
      background:#EFF3FB;
      border-radius:4px;
    }
  }
}
</style>
